from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-13 14:04:55.238703
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 13, Jul, 2022
Time: 14:05:03
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.7758
Nobs: 716.000 HQIC: -50.1287
Log likelihood: 8971.91 FPE: 1.35825e-22
AIC: -50.3507 Det(Omega_mle): 1.19885e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298656 0.057228 5.219 0.000
L1.Burgenland 0.103966 0.037569 2.767 0.006
L1.Kärnten -0.109701 0.019922 -5.507 0.000
L1.Niederösterreich 0.211211 0.078544 2.689 0.007
L1.Oberösterreich 0.107618 0.076848 1.400 0.161
L1.Salzburg 0.257428 0.040221 6.400 0.000
L1.Steiermark 0.043745 0.052366 0.835 0.404
L1.Tirol 0.110388 0.042524 2.596 0.009
L1.Vorarlberg -0.064182 0.036665 -1.751 0.080
L1.Wien 0.046228 0.067822 0.682 0.495
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.047409 0.119703 0.396 0.692
L1.Burgenland -0.034501 0.078582 -0.439 0.661
L1.Kärnten 0.041131 0.041670 0.987 0.324
L1.Niederösterreich -0.166584 0.164289 -1.014 0.311
L1.Oberösterreich 0.422765 0.160742 2.630 0.009
L1.Salzburg 0.288404 0.084130 3.428 0.001
L1.Steiermark 0.100143 0.109533 0.914 0.361
L1.Tirol 0.318792 0.088947 3.584 0.000
L1.Vorarlberg 0.026599 0.076691 0.347 0.729
L1.Wien -0.036872 0.141861 -0.260 0.795
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188027 0.029282 6.421 0.000
L1.Burgenland 0.089495 0.019223 4.656 0.000
L1.Kärnten -0.007946 0.010193 -0.780 0.436
L1.Niederösterreich 0.264586 0.040188 6.584 0.000
L1.Oberösterreich 0.137321 0.039320 3.492 0.000
L1.Salzburg 0.045980 0.020580 2.234 0.025
L1.Steiermark 0.019933 0.026794 0.744 0.457
L1.Tirol 0.091528 0.021758 4.207 0.000
L1.Vorarlberg 0.057572 0.018760 3.069 0.002
L1.Wien 0.114675 0.034702 3.305 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111849 0.029789 3.755 0.000
L1.Burgenland 0.045541 0.019555 2.329 0.020
L1.Kärnten -0.013698 0.010370 -1.321 0.187
L1.Niederösterreich 0.189965 0.040884 4.646 0.000
L1.Oberösterreich 0.302481 0.040001 7.562 0.000
L1.Salzburg 0.108058 0.020936 5.161 0.000
L1.Steiermark 0.105276 0.027258 3.862 0.000
L1.Tirol 0.103891 0.022135 4.694 0.000
L1.Vorarlberg 0.068397 0.019085 3.584 0.000
L1.Wien -0.022325 0.035303 -0.632 0.527
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134684 0.054270 2.482 0.013
L1.Burgenland -0.051846 0.035627 -1.455 0.146
L1.Kärnten -0.044347 0.018892 -2.347 0.019
L1.Niederösterreich 0.155344 0.074484 2.086 0.037
L1.Oberösterreich 0.139513 0.072876 1.914 0.056
L1.Salzburg 0.286657 0.038142 7.515 0.000
L1.Steiermark 0.047863 0.049659 0.964 0.335
L1.Tirol 0.167153 0.040326 4.145 0.000
L1.Vorarlberg 0.093030 0.034770 2.676 0.007
L1.Wien 0.074330 0.064316 1.156 0.248
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055384 0.043197 1.282 0.200
L1.Burgenland 0.037790 0.028357 1.333 0.183
L1.Kärnten 0.050802 0.015037 3.378 0.001
L1.Niederösterreich 0.217471 0.059286 3.668 0.000
L1.Oberösterreich 0.295751 0.058006 5.099 0.000
L1.Salzburg 0.048031 0.030360 1.582 0.114
L1.Steiermark 0.000820 0.039527 0.021 0.983
L1.Tirol 0.141859 0.032098 4.420 0.000
L1.Vorarlberg 0.071699 0.027675 2.591 0.010
L1.Wien 0.081305 0.051193 1.588 0.112
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174999 0.051621 3.390 0.001
L1.Burgenland -0.003014 0.033888 -0.089 0.929
L1.Kärnten -0.063019 0.017970 -3.507 0.000
L1.Niederösterreich -0.081161 0.070849 -1.146 0.252
L1.Oberösterreich 0.194947 0.069319 2.812 0.005
L1.Salzburg 0.056836 0.036281 1.567 0.117
L1.Steiermark 0.235513 0.047235 4.986 0.000
L1.Tirol 0.497678 0.038358 12.975 0.000
L1.Vorarlberg 0.042743 0.033072 1.292 0.196
L1.Wien -0.052995 0.061177 -0.866 0.386
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172751 0.059173 2.919 0.004
L1.Burgenland -0.010449 0.038845 -0.269 0.788
L1.Kärnten 0.062987 0.020598 3.058 0.002
L1.Niederösterreich 0.205740 0.081213 2.533 0.011
L1.Oberösterreich -0.071897 0.079459 -0.905 0.366
L1.Salzburg 0.213258 0.041588 5.128 0.000
L1.Steiermark 0.123225 0.054145 2.276 0.023
L1.Tirol 0.071096 0.043969 1.617 0.106
L1.Vorarlberg 0.115814 0.037910 3.055 0.002
L1.Wien 0.120147 0.070126 1.713 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.362019 0.034137 10.605 0.000
L1.Burgenland 0.006336 0.022410 0.283 0.777
L1.Kärnten -0.023382 0.011883 -1.968 0.049
L1.Niederösterreich 0.217276 0.046852 4.637 0.000
L1.Oberösterreich 0.201268 0.045841 4.391 0.000
L1.Salzburg 0.043279 0.023992 1.804 0.071
L1.Steiermark -0.014801 0.031237 -0.474 0.636
L1.Tirol 0.104620 0.025366 4.124 0.000
L1.Vorarlberg 0.070261 0.021871 3.213 0.001
L1.Wien 0.035196 0.040456 0.870 0.384
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037553 0.138970 0.192660 0.155438 0.116002 0.103047 0.059408 0.216366
Kärnten 0.037553 1.000000 -0.015675 0.133859 0.055919 0.095176 0.435596 -0.053081 0.093643
Niederösterreich 0.138970 -0.015675 1.000000 0.335231 0.141296 0.293342 0.092047 0.175257 0.313535
Oberösterreich 0.192660 0.133859 0.335231 1.000000 0.227654 0.324250 0.175735 0.162810 0.262071
Salzburg 0.155438 0.055919 0.141296 0.227654 1.000000 0.138090 0.116567 0.137945 0.129195
Steiermark 0.116002 0.095176 0.293342 0.324250 0.138090 1.000000 0.145236 0.133996 0.070194
Tirol 0.103047 0.435596 0.092047 0.175735 0.116567 0.145236 1.000000 0.110361 0.142221
Vorarlberg 0.059408 -0.053081 0.175257 0.162810 0.137945 0.133996 0.110361 1.000000 -0.003382
Wien 0.216366 0.093643 0.313535 0.262071 0.129195 0.070194 0.142221 -0.003382 1.000000